#ifndef GL_MAPPING_HANDLER_H
#define GL_MAPPING_HANDLER_H

class GLMappingHandler : public GLHandler
{
public:
	GLMappingHandler(GLView * glView, Model * model): GLHandler(glView, model){}

public:

	int lButtonDown(WPARAM state, int x, int y)
	{
		//::MessageBox(0, L"Draw.", L"Error", MB_ICONEXCLAMATION | MB_OK);
		model->setMousePos(model->mappingView, x, y);
		if(state == MK_LBUTTON)
		{
			model->setMouseLeft(model->mappingView, true);
		}
		return 0;
	}
	
	int lButtonUp(WPARAM state, int x, int y)
	{
		model->setMousePos(model->mappingView, x, y);
		//::MessageBox(0, L"Draw.", L"Error", MB_ICONEXCLAMATION | MB_OK);
		if (model->mappingView.viewMode == EDIT)
		{
			model->brush_paint();
			model->setUpdated(model->cullingView, true);
			model->setUpdated(model->mappingView, true);
		}
		else if (model->mappingView.viewMode == VIEW)
		{
			model->setUpdated(model->mappingView, false);
		}
		return 0;
	}
	
	int rButtonDown(WPARAM state, int x, int y)
	{
		model->setMousePos(model->mappingView, x, y);
		if(state == MK_RBUTTON)
		{
			model->setMouseRight(model->mappingView, true);
		}
		return 0;		
	}
	int rButtonUp(WPARAM state, int x, int y)
	{
		model->setMousePos(model->mappingView, x, y);
		model->setMouseRight(model->mappingView, false);
		if (model->mappingView.viewMode == EDIT)
		{
			
		}
		return 0;
	}
	int keyUp(int key, LPARAM lParam) 
	{
		return 0;
	}
	int size(int w, int h, WPARAM type)
	{
		model->setUpdated(model->mappingView, true);
		model->setWindowSize(model->mappingView, w, h);
		return 0; 
	}
	int mouseMove(WPARAM state, int x, int y)
	{
		if (model->mappingView.viewMode == VIEW)
		{
			if(state == MK_LBUTTON)
			{
				if (model->getMouseLeft(model->mappingView) )
				{	
					switch (model->mappingView.lbf)
					{
					case TRANSLATE:	
						model->translateCamera(model->mappingView, x, y);
						model->setUpdated(model->mappingView, true);
						break;
					case ROTATE :
						model->rotateCamera(model->mappingView, x, y);
						model->setUpdated(model->mappingView, true);
						break;
					default : ;
					}
				}
			}
			if(state == MK_RBUTTON)
			{
				if (model->getMouseRight(model->mappingView))
				{
					//Fix ME here. 
					//We should mapingView, not cullingView
					model->zoomCamera(model->mappingView, y);
					//model->setUpdated(model->cullingView, true);
					model->setUpdated(model->mappingView, true);
				}
			}
		}
		else
		{
			//In edit mode
			
			switch (state)
			{
			case MK_LBUTTON :
				if (model->getMouseLeft(model->mappingView))
				{

				}
				break;
			case MK_RBUTTON :	
				break;
			default:
				//No button down
				//model->moveMapBrush(model->mappingView, x, y);
				//model->setUpdated(model->mappingView, true);
				;
			}
		}

		return 0;
	}
	
};

#endif
